using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;

using VCDepend.Engine.Graphviz;
using VCDepend.Engine;

namespace VCDepend.Tests
{
	public class Support
	{
		public static Stream LoadResourceStream(string name)
		{
			Assembly a = Assembly.GetExecutingAssembly();
			return a.GetManifestResourceStream(name);
		}

		public static string SerializeDotObject(IDotSerializable serializable)
		{
			StringBuilder result = new StringBuilder();
			using (StringWriter writer = new StringWriter(result))
			{
				serializable.Serialize(writer);
			}

			return result.ToString();
		}

    public static bool Contains(string value, string candidate)
    {
      return (value.IndexOf(candidate) != -1);
    }

    public static bool ContainsLine(string value, string candidate)
    {
      string candidateLine = Environment.NewLine + candidate + Environment.NewLine;
      return (value.IndexOf(candidateLine) != -1);
    }

    public static bool Matches(string value, string pattern)
    {
      return Regex.IsMatch(value, pattern);
    }
	}
}
